from django.core.files.storage import Storage
from fdfs_client.client import *  
from dailyfresh import settings
class FDFSStorage(Storage):
    def _open(self,name,mode='rb'):
        pass
    def _save(self,name,content):
        conf=get_tracker_conf('./utils/fastdfs/client.conf')
        client=Fdfs_client(conf)
        res=client.upload_appender_by_buffer(content.read())
        if res.get('Status') !='Upload successed.':
            raise Exception("上传文件失败")
        filename=res.get("Remote file_id")
        print(filename)
        return filename.decode('utf8')
    def exists(self,name):
        return False
    def url(self,name):
        return "http://"+settings.NGINX_FLIE+"/"+name
